package data.entity;

import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;

/**
 * @author fank
 * @date 2018-08-23 15:30
 * @desc 游戏记录表复合主键(玩家id, 房间id)
 **/
@Embeddable
public class PK implements Serializable {
    private static final long serialVersionUID = -3304319243957837925L;

    private long playerId;
    private int roomId;

    public static PK valueOf(int roomId, long playerId) {
        PK pk = new PK();
        pk.playerId = playerId;
        pk.roomId = roomId;
        return pk;
    }

    public long getPlayerId() {
        return playerId;
    }

    public void setPlayerId(long playerId) {
        this.playerId = playerId;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PK pk = (PK) o;
        return playerId == pk.playerId &&
                roomId == pk.roomId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(playerId, roomId);
    }
}
